import React, { Component } from 'react';
import { withRouter, Link, Switch, Route } from 'react-router-dom'
import { Spin } from 'antd';

import "./../static/loading.styl"
import $ from "jquery"

export default class Loading extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      loading: true
    }
  }

  pageSize() {
    $(".loading").width(document.body.clientWidth).height(document.body.clientHeight);
    $(window).resize(function () {
      $(".loading").width(document.body.clientWidth).height(document.body.clientHeight);
    })
  }
  close() {
    let timer;
    // setTimeout(()=>{
  
    // },1000)
    // window.addEventListener('storage',function(){
    //   alert(1111)
    // })
    let flag = true;
   setInterval(()=>{
    if(sessionStorage.getItem('loading') == 'block'){
      if(!flag)return;
      flag = false;
      $('.loading').show()
      // timer = setTimeout(()=>{
      //   sessionStorage.setItem('loading','none')
      // },1000)
    }else{
      flag = true;
      // clearTimeout(timer);
      $('.loading').hide()
    }
   },10)
  }
  componentDidMount() {
    this.pageSize();
    this.close();
  }

  render() {
    return (
      <div className="loading" >
        <Spin size="large" />
      </div>
    );
  }
}